<template>
  <div class="app-container">
    <div class="filter-container"></div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="编号"  align="center" width="60" >
        <template slot-scope="scope">
          <span>  {{ scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" width="160px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.slUserByUid.nickname }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户手机号" width="160px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.slUserByUid.phone }}</span>
        </template>
      </el-table-column>
       <el-table-column label="项目名称"  align="center">
        <template slot-scope="{row}">
          <span>{{ row.slProjectByPid.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文件名称" min-width="200px"> 
        <template slot-scope="{row}">
          
            <div v-for="(item,itemIndex) in row.contractFile " :key="itemIndex">
          <img :src="item" alt="" style="width:50px;height:30px">
        </div>
        </template>
      </el-table-column>
    
     
     
      <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row,$index}">
                <el-button type="primary" size="mini" >
                  查看文件
                </el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
import { GQL } from '@/api/article'


export default {
 
  data() {
    return {
      tableKey: 0,
      uid:'',
      list: null,
      listLoading: true,
     
      showReviewer: false,
   
    }
  },
  created(e) {
      let id=this.$route.query.id;
        this.uid = id
     this.getList()
  },
  methods: {
    getList(id) {
        this.listLoading = true
        const query = {
            "operationName": "allSlProjectContractFiles",
            "query": "query allSlProjectContractFiles($filter: SlProjectContractFileFilter) { allSlProjectContractFiles(filter:$filter) { nodes { uid pid slUserByUid { uid nickname phone } slProjectByPid { title pid } filename filepath id createtime } } }",
            "variables":{ "filter": { "uid": { "equalTo": this.id } } }
        }
       GQL(query).then(response => {
          
        //    console.log('1----',response)
        this.list = response.data.allSlProjectContracts.nodes
        this.total = response.data.allSlProjectContracts.totalCount
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
      
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleCommand(row){
         const num = "1";
         let query = {
            "operationName": "updateSlProjectContractById",
            "query": "mutation updateSlProjectContractById($input: UpdateSlProjectContractByIdInput!) { updateSlProjectContractById(input: $input) { slProjectContract { id } } }",
            "variables": { "input": { "id": row.id, "slProjectContractPatch": { "status": num } } }
            
          }

          GQL(query).then((res) => {
              console.log('res---',res)
               if(res.errors){
                  this.$notify({
                    title: '审核失败',
                    message: '审核项目失败',
                    type: 'error',
                    duration: 2000
                  })
              }else{
                  this.$notify({
                    title: '审核成功',
                    message: '审核项目成功',
                    type: 'success',
                    duration: 2000
                  })
                  this.handleFilter()
              }
       
          })
    },
     handleCommand2(row){
        const num = "2";
        let query = {
            "operationName": "updateSlProjectContractById",
            "query": "mutation updateSlProjectContractById($input: UpdateSlProjectContractByIdInput!) { updateSlProjectContractById(input: $input) { slProjectContract { id } } }",
           "variables": { "input": { "id": row.id, "slProjectContractPatch": { "status": num } } }
           
          }
          GQL(query).then((res) => {
               if(res.errors){
                  this.$notify({
                    title: '审核失败',
                    message: '审核项目失败',
                    type: 'error',
                    duration: 2000
                  })
              }else{

                  this.$notify({
                    title: '审核成功',
                    message: '资料已被拒绝',
                    type: 'success',
                    duration: 2000
                  })
                  this.handleFilter()
              }
       
          })
    },


  }
}
</script>
<style scoped>
.demonstration {
  display: block;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}
 .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
